package com.ruoyi.web.domain.warning;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.time.LocalDateTime;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.web.utils.v2.V2DeviceInfo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * 预警记录
 *
 * @author fwx
 * @since 2024-01-30 15:08:07
 */
@Data
@TableName("tt_warning_factor_record")
@ApiModel(value = "WarningRecord对象", description = "预警记录")
public class WarningFactorRecord implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    @ApiModelProperty("预警配置id表")
    @TableField("config_id")
    private Integer configId;

    @ApiModelProperty("产品id")
    @TableField("product_id")
    private Long productId;

    @ApiModelProperty("设备id")
    @TableField("device_id")
    private String deviceId;

    @ApiModelProperty("设备名字")
    @TableField("device_name")
    private String deviceName;

    @ApiModelProperty("设备类型")
    @TableField("device_type")
    private String deviceType;

    @ApiModelProperty("因子名称")
    @TableField("factor_name")
    private String factorName;

    @ApiModelProperty("因子key")
    @TableField("factor_key")
    private String factorKey;

    @ApiModelProperty("因子类型")
    @TableField("factor_type")
    private String factorType;

    @ApiModelProperty("预警名称")
    @TableField("warning_name")
    private String warningName;

    @ApiModelProperty("预警时间")
    @TableField("warning_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime warningTime;

    @ApiModelProperty("预警结束时间")
    @TableField("warning_end_time")
    private LocalDateTime warningEndTime;

    @ApiModelProperty("预警等级")
    @TableField("warning_level")
    private String warningLevel;

    @ApiModelProperty("异常值")
    @TableField("abnormal_value")
    private String abnormalValue;

    @ApiModelProperty("预警内容")
    @TableField("warning_content")
    private String warningContent;

    @ApiModelProperty("决策建议")
    @TableField("warning_recommend")
    private String warningRecommend;

    @ApiModelProperty("是否发送短信")
    @TableField("is_send_sms")
    private Integer isSendSms;

    @ApiModelProperty("是否发送邮件")
    @TableField("is_send_email")
    private Integer isSendEmail;

    @ApiModelProperty("是否查看")
    @TableField("is_click")
    private Integer isClick;

    @ApiModelProperty("创建时间")
    @TableField("crt_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime crtTime;

    @ApiModelProperty("设备信息")
    @TableField(exist = false)
    private V2DeviceInfo deviceInfo;

    /**
     * @desc
     * @author fwx 2024/2/23 11:34
     **/
    public String buildEmailContent(){
        String warningTime = DateUtils.formatDateTime(this.warningTime);

        String format = String.format("[物联网平台] -%s告警%s级,在%s发生,设备名:%s(ID:%s),发生情况为:%s",
                this.warningName,this.warningLevel, warningTime,
                this.getDeviceName(),this.getDeviceId(),this.getAbnormalValue());

        return format;
    }
}
